<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.box{
				position: absolute;
				top: 0;
				left: 0;
				width: 100px;
				height: 100px;
				background-color: orange;
			}
		</style>
	</head>
	<body>
		<div class="box"></div>
		<script src="./js/utils.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var box = document.getElementsByClassName('box')[0];
			
			elemDrag(box);
			
			function elemDrag(elem) {
				var x,
					y;
				
				addEvent(elem, 'mousedown', function(e){
					var e = e || window.event;
					x = pagePos(e).X - getStyles(elem, 'left');
					y = pagePos(e).Y - getStyles(elem, 'top');
					
					addEvent(document, 'mousemove', mouseMove);
					addEvent(document, 'mouseup', mouseUp);
					canceBubble(e);
					preventEvent(e);
				})
				
				function mouseMove(e){
					var e = e || window.event;
					elem.style.left = pagePos(e).X - x + 'px';
					elem.style.top = pagePos(e).Y - y + 'px';
				}
				
				function mouseUp(e){
					var e = e || window.event;
					removeEvent(document, 'mousemove', mouseMove);
					removeEvent(document, 'mouseup', mouseUp);
				}
			}
		</script>
	</body>
</html>
